#include <head.h>
#include "./wrap.h"
void fn(char *p);
int main(int argc ,char** argv)
{
    int serversocket = Socket(AF_INET, SOCK_DGRAM, 0);
    char buf[BUFSIZ];
    struct sockaddr_in  addr ;
    socklen_t socklen;
    memset(&addr,0,sizeof(addr));
    addr.sin_family =AF_INET;
    addr.sin_port = htons(9000);
    int r=  inet_pton(AF_INET,"127.0.0.1",&(addr.sin_addr.s_addr));
    if(r ==0){
        sys_error("inet_pton");
    }

    while(1){
        CLEAR_ARRAY(buf);
        r= Read(STDIN_FILENO,buf,sizeof(buf));
        if(0 == strncmp("quit",buf,4)){
            break;
        }
        else{
            sendto(serversocket,buf,r,0,(struct sockaddr*)&addr,sizeof(addr));
        }
        CLEAR_ARRAY(buf);
        socklen =sizeof(addr);
        r= recvfrom(serversocket,buf,sizeof(buf),0,(struct sockaddr*)&addr,&socklen);
        Write(STDOUT_FILENO,buf,r);
    }
    
    Close(serversocket);
    return 0;
}
void fn(char *p)
{
    if(!p){
        return;
    }
    while (*p)
    {
        *p =toupper(*p);
        p++;
    }
    
}
